	<%@page import="com.situ.student.entity.PageBean"%>
	<%@page import="com.situ.student.entity.Student"%>
	<%@page import="java.util.List"%>
	<%@page import="com.situ.student.service.impl.StudentServiceImpl"%>
	<%@page import="com.situ.student.service.IStudentService"%>
	<%@ page language="java" contentType="text/html; charset=UTF-8"
	    pageEncoding="UTF-8"%>
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" href="lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
	<style type="text/css">
		.align-center{
		    width: 800px;
			margin : 10px auto;
		}
		table{
			table-layout : fixed;
			word-break : break-all;
		}
	</style>
	</head>
	<body>
		<%
			PageBean pageBean = (PageBean)request.getAttribute("pageBean");
		%>
		<div class="align-center">
			<a href="student_add.jsp">添加</a>
			
			<!--<%=request.getContextPath()%>-->  <!-- /Java1807Web -->
			<!--<form action="<%=request.getContextPath()%>/student?method=list" method="post"></form>-->
				
				<a href="javascript:deleteAll()">批量删除</a>
				<form action="<%=request.getContextPath()%>/student?method=pageList" method="post"></form>
				姓名：<input type="text" name="name"/>
				<input type="submit" value="搜索"/>
				
				
				<form action="" id="mainForm" method="post">
				<!-- 遍历List<Student> list -->
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
						<td><input type="checkbox" id="selectAlls" onclick="selectAll()"/></td>
						<td>ID</td>
						<td>姓名</td>
						<td>年龄</td>
						<td>性别</td>
						<td>修改</td>
						<td>删除</td>
						</tr>
							<% 
							for(Student student :pageBean.getList()){
							%>	
								<tr>
									<td><input type="checkbox" name="selectIds" value="<%=student.getId()%>"/></td>
									<td><%=student.getId()%></td>
									<td><%=student.getName()%></td>
									<td><%=student.getAge()%></td>
									<td><%=student.getGender()%></td>
									<td><a href="<%=request.getContextPath()%>/student?method=toUpdate&id=<%=student.getId()%>">修改</a></td>
									<td><a href="javascript:deleteById(<%=student.getId()%>)">删除</a></td>
								</tr>
							<% 	
							}
							%>
							
					</table>
				</form>
				
				
			</table>
			<nav aria-label="Page navigation">
			  <ul class="pagination">
			   	  <!-- 上一页 开始 -->
			      <%
			      	  if (pageBean.getPageNo() == 1) {//如果当前已经是第一页，就不能点击上一页
			      %>	
			      	  <li class="disabled">
			      		<a  href="#" aria-label="Previous">
				       		<span aria-hidden="true">&laquo;</span>
				   		</a>
				   	  </li>
			      <%
			         } else {
			      %>
			      	  <li >
					      <a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=pageBean.getPageNo()-1%>&pageSize=3" aria-label="Previous">
					      	<span aria-hidden="true">&laquo;</span>
					      </a>
					  </li>
				  <%
			      	  }
			      %>
			       <!-- 上一页 结束 -->
			       
			    <%
			    	for (int i = 1; i <= pageBean.getTotalPage(); i++) { //最大的数
			    		if (i == pageBean.getPageNo()) {
			    %>
							<li class="active"><a href="#"><%=i%></a></li>
			    <% 		
			    		} else {
			    %>
							<li><a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=i%>&pageSize=3"><%=i%></a></li>
				<%
			    		}
			    	}
			    %>
			    
			     <!-- 下一页 开始 -->
			    <% 
			     if(pageBean.getPageNo() == pageBean.getTotalPage()){
			    %>	 
			    	 <li class="disabled">
			      		<a  href="#" aria-label="Previous">
				        	<span aria-hidden="true">&raquo;</span>
				   		</a>
				   	  </li>
			     	<% 
			     		}else{
			     	%>
			    	 
			    	 <li >
				      <a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=pageBean.getPageNo()+1%>&pageSize=3" aria-label="Previous">
				        <span aria-hidden="true">&raquo;</span>
				      </a>
				  </li>
			     
			     <%
			     		  }
			     %>
			     <!-- 下一页 结束 -->
			  </ul>
			</nav>
		</div>
		
		<!--bootstrap.js用到了jquery，所以要首先引入jquery -->
		<script type="text/javascript" src="lib/jquery/jquery-1.11.1.js" ></script>
		<script type="text/javascript" src="lib/bootstrap-3.3.7-dist/js/bootstrap.js" ></script>
		<script type="text/javascript">
			function deleteById(id) {
				//用户点了确定，confirm返回的是true，
				//用户点了取消，confirm返回的是false，
				var isDel = confirm("您确认要删除么？");
				if (isDel) {
					location.href = "<%=request.getContextPath()%>/student?method=deleteById&id=" + id;
				} 
			}
			
				function selectAll(){   
				//得到上面全选、反选按钮的状态
				var isChecked = $("#selectAlls").prop("checked");
				//下面所有checkbox的状态和上面全选、反选checkbox的状态一致
				$("input[name=selectIds]").prop("checked", isChecked);
				}		
				function deleteAll(){
					$("#mainForm").attr("action", "<%=request.getContextPath()%>/student?method=deleteAll");
					//用代码方式提交表单
					$("#mainForm").submit();
					//提示
					var isDels = confirm("您确认要删除么？");
					if (isDels) {
						location.href = "<%=request.getContextPath()%>/student?method=pageList" + all;
					} 
				}
		</script>
	</body>
	</html>